//
//  HttpRequestManager.m
//  i优购商城
//
//  Created by qianfeng on 15/9/14.
//  Copyright (c) 2015年 qianfeng. All rights reserved.
//

#import "HttpRequestManager.h"
#import "AFNetworking.h"
#import "Interface.h"
@implementation HttpRequestManager
{
    NSString*_urlString;
}

+(instancetype)shareInstance
{
    static HttpRequestManager*manager=nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken,^{
        manager=[[HttpRequestManager alloc]init];
        
    });
    return manager;
    
}

-(void)getHomeDataSuccess:(httpSucesss)success  Failure:(httpFailure)failure
{
    AFHTTPRequestOperationManager*mng=[AFHTTPRequestOperationManager manager];
    mng.responseSerializer=[AFHTTPResponseSerializer serializer];
    [mng GET:kHome parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
           responseObject=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        success(responseObject);
       
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
      
        failure(error);
        
    }];
    

}

-(void)getBrandDataBypage:(int)num Success:(httpSucesss)success  Failure:(httpFailure)failure
{
    AFHTTPRequestOperationManager*mng=[AFHTTPRequestOperationManager manager];
     mng.responseSerializer=[AFHTTPResponseSerializer serializer];
    [mng POST:kBrand parameters:@{@"page":@(num)} success:^(AFHTTPRequestOperation *operation, id responseObject) {
          responseObject = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        success(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
       
        failure(error);
        
    }];

}

-(void)getListDataByItemID:(NSString*)itemID Andidentify:(int)ident  Andpage:(int)page Success:(httpSucesss)success Failure:(httpFailure)failure
{
    AFHTTPRequestOperationManager*mng=[AFHTTPRequestOperationManager manager];
    mng.responseSerializer=[AFHTTPResponseSerializer serializer];
  
    if (ident==1) {
        _urlString=[NSString stringWithFormat:kListamountDown,itemID,page ];
    }
    else if (ident==2)
    {
    _urlString=[NSString stringWithFormat:kListamountUp,itemID,page ];
    }
    else if (ident==3)
    {
        _urlString=[NSString stringWithFormat:kListPriceDown,itemID,page ];
    }
    else if (ident==4)
    {
        _urlString=[NSString stringWithFormat:kListPriceUp,itemID,page ];
    }
    else if (ident==5)
    {
        _urlString=[NSString stringWithFormat:kListDiscountDown,itemID,page ];
    }
    else if (ident==6)
    {
        _urlString=[NSString stringWithFormat:kListDiscountUp,itemID,page ];
    }
    else if (ident==7)
    {
        _urlString=[NSString stringWithFormat:kListNewDown,itemID,page ];
    }
    else
    {
        _urlString=[NSString stringWithFormat:kListNewUp,itemID,page ];
    }
    
    [mng POST:_urlString  parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        responseObject = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        success(responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failure(error);
        
    }];
    

}

-(void)getCategoryDataSuccess:(httpSucesss)success Failure:(httpFailure)failure
{
    AFHTTPRequestOperationManager*mng=[AFHTTPRequestOperationManager manager];
    mng.responseSerializer=[AFHTTPResponseSerializer serializer];
    [mng GET:Kcategory parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        responseObject=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        success(responseObject);
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        failure(error);
        
    }];


}




@end